package logger

import (
	"github.com/gin-gonic/gin"

	"go-toy/constant"
	"go-toy/util"

	loggerInterface "go-toy/middleware/logger/interf"
)

type Factory struct {
}

func (f *Factory) Builder() (w *loggerInterface.Writer) {
	logConfig := util.Viper.GetStringMap("log")
	if len(logConfig) > 0 {
		driver := logConfig["drive"]
		switch driver {
		case constant.LOG_DRIVE_GO:
			w = &GoWriterInstance
		case constant.LOG_DRIVE_ZAP:
			w = &ZapWriterInstance
		default:
			w = &NoneWriterInstance
		}
	} else {
		w = &NoneWriterInstance
	}
	return w
}

func (f *Factory) Handle() gin.HandlerFunc {
	w := *f.Builder()
	return w.Handle()
}

var FactoryInstance loggerInterface.Factory = &Factory{}
